#ifndef __MOTOR_CONTROL_H__
#define __MOTOR_CONTROL_H__
#include "main.h"
#include "pid.h"
typedef struct 
{
	/* 电机id */
	int     ID;
	/* 电调返回的数据 */
	int16_t esc_back_position;       //电机电调返回的位置(码盘值)
	int16_t esc_back_speed;          //电机电调返回的转速
	int16_t esc_back_given_current;  //电机电调返回的电流
	int16_t esc_back_temperature;    //电机电调返回的温度
	/* 处理成连续的码盘值 */
	uint8_t process_position_flag;   //处理码盘值标志
	int16_t esc_back_position_last;  //电调返回的上一次位置(码盘值)
	int16_t circle_num;              //电机旋转圈数
	int64_t serial_position;         //最终处理后的码盘值
	double position_angle;          //将码盘处理成角度

	float   gyro_speed;
	float   gyro_angle;
	float   gyro_angle_last;
	float   gyro_error;

	int16_t SpeedTarget;
  int16_t SpeedBack;

	double yawEncodTarget;
	double pitEncodTarget;
	double PositionTarget;
	int64_t PositionBack;
	double turnMove;
	int64_t turnMove_Last;
	float visTarget;
	float visPitTarget;

	uint16_t coolingheat;
	uint16_t coolingheat_limit;
	
	struct
	{
		float __position;
		float __velocity;
		float __torque;
	}TmotorData_t;
}motorData_t;


void PID_AbsParam_Init(PID_AbsoluteType *pid, float p, float i, float d, float erriLim, int16_t MaxOutCur);
void PID_AbsParam_Set(PID_AbsoluteType *pid, float p, float i, float d, float erriLim, int16_t MaxOutCur);
int16_t motor_speed_loop_pid_control(PID_AbsoluteType *spd_pid, float get, float target);
float motor_cascade_loop_pid_control(PID_AbsoluteType *pos_pid, PID_AbsoluteType *spd_pid, float externGet, float externSet, float internGet);
void process_motor_encoder_to_serial(motorData_t *motor);
void CANTx_SendCurrent(CAN_HandleTypeDef *hcan,uint32_t id,int16_t current1,int16_t current2,int16_t current3,int16_t current4);

#endif

